package com.liush.srb.core.controller.api;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liush.srb.base.exception.SrbException;
import com.liush.srb.base.util.JwtUtils;
import com.liush.srb.common.HttpClientUtils;
import com.liush.srb.core.pojo.entity.UserInfo;
import com.liush.srb.core.service.UserInfoService;
import com.liush.srb.core.service.WxLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.UUID;

/**
 * @Author: liush
 * @CreateTime: 2023-04-02  15:40
 * @Description: 微信登录模块
 */
@Controller
@Api(tags = "微信登录模块")
@RequestMapping("/api/wx")
public class ApiWxLoginController {

    @Resource
    WxLoginService wxLoginService;

    @ApiOperation("wx登录")
    @GetMapping("login")
    public String wxLogin(HttpSession session) {
        return wxLoginService.wxLogin(session);
    }

    //此方法回调 wx用户已确认授权，他希望得到的响应结果是 登录成功的页面
    //code=091OnB000GtYHP1JTV100Ycznq3OnB0Q&state=3d6be0a4035d839573b04816624a415e
    @ApiOperation("wx用户确认回调")
    @GetMapping("/callback")
    public String callback(String code, //用户授权后的临时票据
                           String state,
                           HttpSession session,
                           HttpServletRequest request) throws Exception {//方式csrf跨站点攻击的唯一字符串
        return wxLoginService.callback(code, state, session, request);
    }
}
